# -*- coding: utf-8 -*-
"""
@Time ： 2023/7/4 22:29
@Auth ： 叶东宇
@File ：slidingWindowMaximum.py
"""
def maxSlidingWindow(nums, k):
    """
    第二个版本，优化了，但是依然超时
    :param nums:
    :param k:
    :return:
    """
    maxlis = []
    if k >= len(nums):
        return [max(nums)]
    else:
        for i in range(len(nums) - k + 1):
            if len(maxlis) == 0:
                maxlis.append(max(nums[:k]))
            else:
                if maxlis[-1] != nums[i - 1:i + k - 1][0]:
                    maxlis.append(max(maxlis[-1], nums[i + k - 1]))
                else:
                    maxlis.append(max(nums[i:i + k]))
    return maxlis

def maxSlidingWindow_1(nums, k):
    """
    最开始版本，超时
    :param nums:
    :param k:
    :return:
    """
    maxlis = []
    if k >= len(nums):
        return [max(nums)]
    else:
        for i in range(len(nums) - k + 1):
            maxlis.append(max(nums[i:i + k]))
    return maxlis




if __name__ == "__main__":
    lis = [1,3,-1,-3,5,3,6,7]
    k = 3
    # print(maxSlidingWindow(lis,k))
